package com.xuhai.blog19.admin.controller;

import com.xuhai.blog19.admin.entity.CategoryEntity;
import com.xuhai.blog19.admin.service.CategoryService;
import com.xuhai.blog19.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author PangJunjie
 * @Date 2023/2/8/008
 */
@RestController
@RequestMapping("/admin/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/page")
    public R page(int page, int limit, CategoryEntity category) {
        return R.ok().data(categoryService.getPage(page, limit, category));
    }

    @GetMapping("/info/{categoryId}")
    public R info(@PathVariable Integer categoryId) {
        return R.ok().data(categoryService.getById(categoryId));
    }

    @PostMapping("/update")
    public R update(@RequestBody CategoryEntity category) {
        categoryService.saveOrUpdate(category);
        return R.ok();
    }

    @DeleteMapping("/delete/{categoryId}")
    public R delete(@PathVariable Integer categoryId) {
        categoryService.delete(categoryId);
        return R.ok();
    }

    @GetMapping("/select")
    public R select() {
        return R.ok().data(categoryService.getSelect());
    }
}
